package main

import (
	"fmt"
	"io"
	"net/http"
)

const form = `
	<html><body>
		<form action="#" method="post" name="bar">
			<input type="text" name="in" />
			<input type="submit" value="Submit">
		</form>
	</html></body>
`

func main() {
	http.HandleFunc("/index", actionIndex)
	http.HandleFunc("/form", actionForm)
	if err := http.ListenAndServe(":9999", nil); err != nil {
		panic(err)
	}
}

func actionIndex(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, "<h1>Hello, Golang</h1>")
}

func actionForm(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "text/html")
	switch req.Method {
	case "GET":
		io.WriteString(w, form)
	case "POST":
		in := req.FormValue("in")
		html := fmt.Sprintf("<h1>Think you for your submit</h1><p>%s</p>", in)
		io.WriteString(w, html)
	}
}
